
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel=stylesheet href='include/hoj.css' type='text/css'>
</head>
<body>
<center>
<div style="width:90%; text-align:left">
<img src="image/logo.png"/>
</div>
<table width=96%> 
	<tr align="center" class='hd' valign="top">
				<th><a href="faqs.php">F.A.Qs</a></th>
		<th><a href="./bbs.php">Web Board</a></th>
		<th><a href="./">Home</a></th>
		<th><a href="./problemset.html">ProblemSet</a></th>
		<th><a href="./status.php">Status</a></th>
		<th><a href="./ranklist.php">Ranklist</a></th>
		<th><a href="./contest.php">Contest</a></th>
		<th><a href=loginpage.php>Login</a></th><th><a href=registerpage.php>Register</a></th>	</tr>
</table>
</center>
<center>
<div class="notice">
	<div>
		<B>Notice:</B>鉴于种种原因，本OJ自下周星期一（3月5号）开始不再全面开放，请各位做好善后事宜，谢谢合作。	</div>
</div>
</center>
</div>
<title>Problem 2546. -- [Ctsc2002]购房计划 -- 衡阳八中OJ离线版-2012-02-29</title><center><h2>2546: [Ctsc2002]购房计划</h2><span class=green>Time Limit: </span>10 Sec&nbsp;&nbsp;<span class=green>Memory Limit: </span>128 MB<br><span class=green>Submit: </span>1&nbsp;&nbsp;<span class=green>Solved: </span>1<br>[<a href='submitpage.php?id=2546'>Submit</a>][<a href='problemstatus.php?id=2546'>Status</a>][<a href='bbs.php?id=2546'>Discuss</a>]</center><h2>Description</h2><div class=content><div><span style="font-size: 12pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bill</span><span style="font-size: 12pt">和</span><span style="font-size: 12pt">Scott</span><span style="font-size: 12pt">是商业对手。他们都计划在</span><span style="font-size: 12pt">Javaville</span><span style="font-size: 12pt">城市购买一幢房子，但是他们希望自己的住宅尽量远离对方的住宅。由于</span><span style="font-size: 12pt">Javaville</span><span style="font-size: 12pt">是一座新兴的城市，所以暂时还没有地图，于是，他们只能从当地人的口中搜集信息，这些信息包括建筑物的位置和建筑物之间的距离。尽管这些信息并不完整，但是它们都是正确的。</span></div>
<div><span style="font-size: 12pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Javaville</span><span style="font-size: 12pt">的街道是一个矩形网格，包含</span><span style="font-size: 12pt">m</span><span style="font-size: 12pt">条东西走向的街道，依次用大写字母</span><span style="font-size: 12pt">A,B,C,&hellip;</span><span style="font-size: 12pt">标识，</span><span style="font-size: 12pt">n</span><span style="font-size: 12pt">条南北走向的街道，依次用数字</span><span style="font-size: 12pt">0,1,2,&hellip;</span><span style="font-size: 12pt">标识。我们把两条街道的交点称为交叉路口，两个交叉路口之间的一段街道称为街区。所有的建筑物都位于交叉路口处，每个交叉路口至多只有一座建筑物。建筑物之间的距离定义为从一座建筑物到另一座建筑物所需经过的最少的街区数。</span></div>
<div><span style="font-size: 12pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12pt">例如，</span><span style="font-size: 12pt">Bill</span><span style="font-size: 12pt">和</span><span style="font-size: 12pt">Scott</span><span style="font-size: 12pt">搜集了以下这些信息：</span></div>
<div style="margin: 0cm 0cm 0pt 42.25pt; text-indent: -21.25pt"><span style="font-size: 12pt">l<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt">城市中有</span><span style="font-size: 12pt">5</span><span style="font-size: 12pt">条东西走向的街道和</span><span style="font-size: 12pt">5</span><span style="font-size: 12pt">条南北走向的街道；</span></div>
<div style="margin: 0cm 0cm 0pt 42.25pt; text-indent: -21.25pt"><span style="font-size: 12pt">l<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt">住宅</span><span style="font-size: 12pt">1</span><span style="font-size: 12pt">位于交叉路口</span><span style="font-size: 12pt">A0</span><span style="font-size: 12pt">；</span></div>
<div style="margin: 0cm 0cm 0pt 42.25pt; text-indent: -21.25pt"><span style="font-size: 12pt">l<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt">邮局位于交叉路口</span><span style="font-size: 12pt">A4</span><span style="font-size: 12pt">；</span></div>
<div style="margin: 0cm 0cm 0pt 42.25pt; text-indent: -21.25pt"><span style="font-size: 12pt">l<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt">学校与住宅</span><span style="font-size: 12pt">1</span><span style="font-size: 12pt">距离</span><span style="font-size: 12pt">4</span><span style="font-size: 12pt">个街区；</span></div>
<div style="margin: 0cm 0cm 0pt 42.25pt; text-indent: -21.25pt"><span style="font-size: 12pt">l<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt">住宅</span><span style="font-size: 12pt">2</span><span style="font-size: 12pt">与邮局距离</span><span style="font-size: 12pt">6</span><span style="font-size: 12pt">个街区；</span></div>
<div style="margin: 0cm 0cm 0pt 42.25pt; text-indent: -21.25pt"><span style="font-size: 12pt">l<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><br clear="all" />
<span style="font-size: 12pt">学校与邮局距离</span><span style="font-size: 12pt">6</span><span style="font-size: 12pt">个街区；</span></div>
<div style="margin: 0cm 0cm 0pt 42.25pt; text-indent: -21.25pt"><span style="font-size: 12pt">l<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><br clear="all" />
<span style="font-size: 12pt">住宅</span><span style="font-size: 12pt">3</span><span style="font-size: 12pt">与邮局距离</span><span style="font-size: 12pt">6</span><span style="font-size: 12pt">个街区；</span></div>
<div style="margin: 0cm 0cm 0pt 42.25pt; text-indent: -21.25pt"><span style="font-size: 12pt"><img alt="" src="/JudgeOnline/upload/201112/1(4).jpg" /></span></div>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">根据以上信息，我们可以得到</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">Javaville</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">城市可能的两种布局。我们发现：住宅</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">1</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，邮局和学校的位置都已经确定了，而住宅</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">2</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以位于</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">C0</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">或</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">E2</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，住宅</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">3</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以位于</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">C0</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">或</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">E2</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。于是，城市中总是存在两座住宅相距</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">6</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个街区（地图</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">1</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">h1</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">h3</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，地图</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">2</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">h1</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">h2</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）。但是，对于确定的两座住宅，我们可以保证的最长距离只有</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">4</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个街区</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman"> (h2</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">h3</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的距离总是</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">4</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个街区</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">)</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。于是，我们要告诉</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">Bill</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">Scott</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，尽管总是存在两座相距</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">6</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个街区的住宅，然而最安全的建议是：一人购买住宅</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">2</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，另一人购买住宅</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">3</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下面给出所求数值的严格定义：</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42.25pt; text-indent: -21.25pt; mso-list: l0 level1 lfo1; tab-stops: list 42.25pt"><span lang="EN-US" style="font-size: 12pt; font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><span style="mso-list: Ignore">l<span style="font: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一个可行的城市布局</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">S</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的直径</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">d(S)</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义为该布局中距离最远的两座住宅之间的距离。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt 42.25pt; text-indent: -21.25pt; mso-list: l1 level1 lfo2; tab-stops: list 42.25pt"><span lang="EN-US" style="font-size: 12pt; font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><span style="mso-list: Ignore">l<span style="font: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对于确定的两座住宅</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">i, j</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，它们的安全系数</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">e[i, j]</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义为在所有可行的城市布局中，住宅</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">i, j</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">之间的距离的最小值。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">Bill</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">Scott</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">希望你编写一个程序，根据他们所搜集到的信息，计算出</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">D</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">E</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。其中：</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">D =min{d(S) }</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">；</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">E =max{e[i, j]}</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。同时你还要给出最安全的购房建议，即所有满足</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">e[i, j]=E</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的住宅</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">i, j</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对于上面的例子，第一种布局的</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">d(S<sub>1</sub>)=6</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，第二种布局的</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">d(S<sub>2</sub>)=6</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。每两座住宅之间的安全系数是：</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">e[1,2]=2</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">e[1,3]=2</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">e[2,3]=4</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。于是：</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">D= min{d(S<sub>1</sub>),d(S<sub>2</sub>)}=6</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">E= max{e[1,2],e[1,3],e[2,3]}=4</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，最安全的购房建议是：住宅</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">2</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与住宅</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">3</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font face="Times New Roman" size="3">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p></div><h2>Input</h2><div class=content><p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第一行包含两个正整数</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">m, n</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">1&lt;=m, n&lt;=10</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">），分别表示东西走向的街道数目和南北走向的街道数目。第二行包含一个整数，表示所搜集到的信息条数</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">t(1&lt;=t&lt;=50)</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。文件从第三行开始每行描述一条所搜集到的信息，每条信息都是以下两种形式之一：</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>name<span style="mso-spacerun: yes">&nbsp; </span>LOCATION<span style="mso-spacerun: yes">&nbsp; </span>r<span style="mso-spacerun: yes">&nbsp; </span>c<o:p></o:p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">或者</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>name<span style="mso-spacerun: yes">&nbsp; </span>DISTANCE<span style="mso-spacerun: yes">&nbsp; </span>d<span style="mso-spacerun: yes">&nbsp; </span>name2<o:p></o:p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1"><font face="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这两种形式分别描述建筑物的位置和建筑物之间的距离。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其中，</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">name</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">name2</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是仅包含数字和小写字母的字符串，长度不超过</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">20</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，表示建筑的名称。</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">r</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">A</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">到</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">J</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">之间的大写字母，</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">c</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是一个数字，表示建筑物所位于的交叉路口。</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">d</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是一个正整数，表示两座建筑物之间的距离。如果建筑物名称的前五个字符是小写字母&ldquo;</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">house</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">&rdquo;，那么表示这是一座可以购买的住宅，否则表示一座非民用的建筑物。如果信息是第二种形式，那么其中的</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">name2</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一定在前面的信息中出现过。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这组信息中至少包含两座可以购买的住宅，至多包含</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">25</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">座不同的建筑物。</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font face="Times New Roman" size="3">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p></div><h2>Output</h2><div class=content><p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第一行包含两个整数，分别表示</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">D</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</span><span lang="EN-US" style="font-size: 12pt"><font face="Times New Roman">E</font></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，之间用一个空格隔开</span></p></div><h2>Sample Input</h2>
			<div class=content><span class=sampledata>5 5<br />
6<br />
house1 LOCATION A 0<br />
postoffice LOCATION A 4<br />
school DISTANCE 4 house1<br />
house2 DISTANCE 6 postoffice<br />
school DISTANCE 6 postoffice<br />
house3 DISTANCE 6 postoffice<br />
</span></div><h2>Sample Output</h2>
			<div class=content><span class=sampledata>6 4</span></div><h2>HINT</h2>
			<div class=content><p></p></div><h2>Source</h2>
			<div class=content><p><a href='problemset.html?search='></a></p></div><center>[<a href='submitpage.php?id=2546'>Submit</a>][<a href='problemstatus.php?id=2546'>Status</a>][<a href='bbs.php?id=2546'>Discuss</a>]</center>﻿<br>

<a href="./"><span class=red>HOME</span></a>
<a href="javascript:history.go(-1)"><span class=red>Back</span></a>

<hr>
<center>
	<div class="footer">
			<a href=setlang.php?lang=ko>한국어</a>&nbsp;
		<a href=setlang.php?lang=cn>中文</a>&nbsp;
		<a href=setlang.php?lang=fa>فارسی</a>&nbsp;
		<a href=setlang.php?lang=en>English</a>&nbsp;
		<a href=setlang.php?lang=th>ไทย</a>
	<br>		<div>版权所有 &copy;2008-2012 WaterPark Organization. | <script src="http://s21.cnzz.com/stat.php?id=2982771&web_id=2982771" language="JavaScript"></script>
</div>
		<div>Based on opensource project <a href="http://hustoj.googlecode.com">hustoj</a>.</div>
	</div>
</center>
</body>
</html>
